package cn.cdeden.system.dubbo;

import cn.cdeden.common.core.utils.MapstructUtils;
import cn.cdeden.system.api.RemoteDeptService;
import cn.cdeden.system.api.domain.vo.RemoteDeptVo;
import cn.cdeden.system.domain.bo.SysDeptBo;
import cn.cdeden.system.domain.vo.SysDeptVo;
import cn.cdeden.system.service.ISysDeptService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 部门服务
 *
 * @author Lion Li
 */
@RequiredArgsConstructor
@Service
@DubboService
public class RemoteDeptServiceImpl implements RemoteDeptService {

    private final ISysDeptService sysDeptService;

    /**
     * 通过部门ID查询部门名称
     *
     * @param deptIds 部门ID串逗号分隔
     * @return 部门名称串逗号分隔
     */
    @Override
    public String selectDeptNameByIds(String deptIds) {
        return sysDeptService.selectDeptNameByIds(deptIds);
    }

    @Override
    public List<RemoteDeptVo> getSuperiorAll(Long deptId) {
//        List<SysDeptVo> superiorAll = sysDeptService.getSuperiorAll(deptId);
        return MapstructUtils.convert(sysDeptService.getSuperiorAll(deptId), RemoteDeptVo.class);
    }

    @Override
    public List<RemoteDeptVo> queryLowerLevel(Long deptId) {
        return MapstructUtils.convert(sysDeptService.queryLowerLevel(deptId), RemoteDeptVo.class);
    }

    @Override
    public List<RemoteDeptVo> selectAll() {
        return sysDeptService.selectAll();
    }

    @Override
    public List<RemoteDeptVo> getByPath(String cName) {
        SysDeptBo sysDeptBo = new SysDeptBo();
        sysDeptBo.setPath(cName);
        List<SysDeptVo> sysDeptVos = sysDeptService.selectDeptList(sysDeptBo);

        return MapstructUtils.convert(sysDeptVos, RemoteDeptVo.class);
    }

    @Override
    public Long saveReturnId(RemoteDeptVo dept) {
        SysDeptBo sysDeptBo = MapstructUtils.convert(dept, SysDeptBo.class);
        sysDeptService.insertDept(sysDeptBo);
        return sysDeptBo.getDeptId();
    }

    @Override
    public RemoteDeptVo getById(Long deptId) {
        SysDeptVo deptVo = sysDeptService.selectDeptById(deptId);

        return MapstructUtils.convert(deptVo, RemoteDeptVo.class);
    }

    @Override
    public List<RemoteDeptVo> getByParentId(Long pid) {
        return MapstructUtils.convert(sysDeptService.findByPid(pid), RemoteDeptVo.class);
    }

    @Override
    public List<RemoteDeptVo> selectUserByDeptName(String deptName) {
        return sysDeptService.selectUserByDeptName(deptName);
    }

    @Override
    public List<RemoteDeptVo> getDeptALlByUser(Long userId) {
        return sysDeptService.getDeptALlByUser(userId);
    }
}
